package com.sailor.config;


import com.sailor.filter.ServerMaintenanceFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

/**
 * 配置一些 web 组件
 *
 * @author sailor
 * @date 2022-09-23
 **/
@Configuration
public class WebFilterConfig {

    @Autowired
    ConfigCenter configCenter;

    @Bean
    public FilterRegistrationBean securityFilterRegistration() {
        FilterRegistrationBean<Filter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(serverMaintenanceFilter());
        registrationBean.addUrlPatterns("/*");
        return registrationBean;
    }

    @Bean
    public Filter serverMaintenanceFilter() {
        return new ServerMaintenanceFilter(configCenter);
    }
}
